import type { Metadata } from 'next'; import { notFound } from 'next/navigation'; import { api, ApiError } from '@/lib/api'; import { countryName } from '@/lib/countries'; import { SITE_NAME } from '@/lib/site'; /** Existence check lives in the segment layout (Next 16: a root `loading.tsx` would soft-404). */ async function load(slug: string) { try { return await api.company(slug); } catch (e) { if (e instanceof ApiError && e.notFound) notFound(); return null; } } export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise { const { slug } = await params; const c = await load(slug); if (!c) return { title: 'Company' }; const about = c.profile?.description ?? c.description ?? ''; const desc = `${c.display_name} (${c.canonical_domain}${c.country ? `, ${countryName(c.country)}` : ''}): ${c.counts.sensors} active sensors, ${c.counts.events} structured events, ${c.counts.changes} historical changes. ${about.length > 220 ? `${about.slice(0, 219).trimEnd()}…` : about}`.trim(); return { title: `${c.display_name} — sensors, timeline and history`, description: desc, alternates: { canonical: `/company/${c.slug}` }, openGraph: { title: `${c.display_name} | ${SITE_NAME}`, description: desc, type: 'profile' }, }; } export default async function CompanyLayout({ params, children }: { params: Promise<{ slug: string }>; children: React.ReactNode }) { const { slug } = await params; await load(slug); return <>{children}; }